package recovers

import (
	"fmt"
	"gitee.com/sunny-zhangqiang/zcache/comm/logger"
	"os"
	"runtime/debug"
)

func Recover() {
	if e := recover(); e != nil {
		stack := string(debug.Stack())
		_, _ = fmt.Fprintf(os.Stderr, "panic: %s: %s\n", e, stack)
		logger.Error("panic: %s: %s\n", e, stack)
	}
}

func RecoverWithExit() {
	if e := recover(); e != nil {
		stack := string(debug.Stack())
		_, _ = fmt.Fprintf(os.Stderr, "panic: %s: %s\n", e, stack)
		logger.Error("panic: %s: %s\n", e, stack)
		os.Exit(111)
	}
}
